package com.smasher.pictures;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;

/**
 * @author luck
 * @date 2021/7/14 3:15 PM
 * @describe ImageLoaderUtils
 */
public class ImageLoaderUtils {

    public static boolean assertValidRequest(Context context) {
        if (context instanceof Activity activity) {
            return !isDestroy(activity);
        } else if (context instanceof ContextWrapper contextWrapper) {
            if (contextWrapper.getBaseContext() instanceof Activity activity) {
                return !isDestroy(activity);
            }
        }
        return true;
    }

    private static boolean isDestroy(Activity activity) {
        if (activity == null) {
            return true;
        }
        return activity.isFinishing() || activity.isDestroyed();
    }

}
